/*
 * File:   AlgorithmTest.cpp
 * Author: momsse
 *
 * Created on 28 nov. 2010, 12:13:19
 */

#include "AlgorithmTest.h"
#include "Algorithm.h"


CPPUNIT_TEST_SUITE_REGISTRATION(AlgorithmTest);

AlgorithmTest::AlgorithmTest() {
}

AlgorithmTest::~AlgorithmTest() {
}

void AlgorithmTest::setUp() {
}

void AlgorithmTest::tearDown() {
}

static int iteration = 0;

static string trace_id() {
    int i = ++iteration;
    ostringstream buffer;
    buffer << i;
    return "graph2/graph_" + buffer.str() + ".dot";
}

void AlgorithmTest::testGreedy_algorithm() {
    Graph* g;
    int nb_sommets = 5;
    double p = 1;

    int nb_colors;
    for (int i = 0; i < 10; i++) {
        g = new Graph(nb_sommets, p);
        nb_colors = greedy_algorithm(g);
        //g->saveOnDotFile(trace_id());
        CPPUNIT_ASSERT(nb_colors <= 5);
    }
}

void AlgorithmTest::testBacktracking_algorithm() {
    Graph* g;
    int k = 2;
    bool result;

    for (int i = 1; i < 10; i++) {
        g = new Graph(i, 1);
        result = backtracking_algorithm(g, k);
        //g->saveOnDotFile(trace_id());
        CPPUNIT_ASSERT(result);
    }

    Graph * g4 = new Graph("graph/g4.txt");
    result = backtracking_algorithm(g4, 4);
    g4->saveOnDotFile("graph/g4_2.dot");
    CPPUNIT_ASSERT(result);

}

void AlgorithmTest::testGreaterClique() {

    Graph * g1 = new Graph("graph/g1.txt");
    g1->saveOnDotFile("graph/g1.dot");
    CPPUNIT_ASSERT_EQUAL(4, greaterClique(g1));

    Graph * g2 = new Graph(5, 1);
    g2->saveOnDotFile("graph/g2.dot");
    CPPUNIT_ASSERT_EQUAL(5, greaterClique(g2));

    Graph * g3 = new Graph("graph/g3.txt");
    g3->saveOnDotFile("graph/g3.dot");
    CPPUNIT_ASSERT_EQUAL(5, greaterClique(g3));

    for (int i = 0; i < 10; i++) {
        Graph * g = new Graph(i, 1);
        CPPUNIT_ASSERT_EQUAL(i, greaterClique(g));
    }


    Graph * g = new Graph(1, 0);
    CPPUNIT_ASSERT_EQUAL(1, greaterClique(g));


    Graph * g4 = new Graph("graph/g4.txt");
    g4->saveOnDotFile("graph/g4.dot");
    CPPUNIT_ASSERT_EQUAL(2, greaterClique(g4));

}

void AlgorithmTest::testNochoice_algorithm() {
    int k = 2;
    Graph * g4 = new Graph("graph/g4.txt");
    bool result = nochoice_algorithm(g4, k);
    g4->saveOnDotFile("graph/g4___.dot");
    CPPUNIT_ASSERT(result);

}
